package com.cheng.example.leetcode.book.t002;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Test1 {

    public static boolean CheckPermutation(String s1, String s2) {
        String[] array1 = s1.split("");
        String[] array2 = s2.split("");

        List list1 = Arrays.stream(array1).collect(Collectors.toList());
        List list11 = new ArrayList(list1);
        List list2 = Arrays.stream(array2).collect(Collectors.toList());

        list1.removeAll(list2);
        list2.removeAll(list11);

        if (list1.size() == 0 && list2.size() == 0) {
            return true;
        } else {
            return false;
        }

    }

    public static boolean CheckPermutation1(String s1, String s2) {
        if (s1 == null || s2 == null) {
            return false;
        }
        int length = s1.length();
        if (length != s2.length()) {
            return false;
        }
        int result = 0;
        char[] s1Char = s1.toCharArray();
        char[] s2Char = s2.toCharArray();
        for (int i = 0; i < s1Char.length; i++) {
            //大致看明白了
            result = result ^ s1Char[i] ^ s2Char[i];
        }
        return result == 0;
    }


    public static void main(String[] args) {
        System.out.println(CheckPermutation1("dabcc中", "cbd中ac"));

//        //1001,
//        // 101
//
        //1100
        //按位异或
//        System.out.println(9^5);
//
//        //0001
//        //按位与
        System.out.println(9&5);
//
//        //1101
//        //按位或
//        System.out.println(9|5);

    }

}
